package com.yiwu.web.controller;

import com.yiwu.common.aspect.ApiOperationLog;
import com.yiwu.common.aspect.ApiVerifyLogin;
import com.yiwu.common.exception.BaseResponse;
import com.yiwu.common.model.vo.file.UploadFileRspVO;
import com.yiwu.common.utils.ResultUtil;
import com.yiwu.web.service.FileService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @version 1.0
 * @description TODO
 * @date 2024/5/21 18:50
 */
@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private FileService fileService;


    @ApiOperationLog
    @ApiVerifyLogin
    @PostMapping("/upload")
    @Operation(summary = "文件上传")
    public BaseResponse<UploadFileRspVO> uploadFile(@RequestParam MultipartFile file, HttpServletRequest request) {
        UploadFileRspVO result = fileService.uploadFile(file);
        return ResultUtil.success(result);
    }

    @ApiOperationLog
    @ApiVerifyLogin
    @PostMapping("/img/upload")
    @Operation(summary = "文件上传")
    public BaseResponse<UploadFileRspVO> sendImage(@RequestParam MultipartFile file, HttpServletRequest request) {
        UploadFileRspVO result = fileService.sendImage(file);
        return ResultUtil.success(result);
    }
}
